#! /usr/bin/python
# -*- coding: cp1250 -*-

import re
import string
import datetime
from decimal import Decimal as D
import pepe.p_txt.bigtxt as bt

lino = 0
#amtDr = D(0) # as decimal
amtDr = 0
#amtCr = D(0) # as decimal
amtCr = 0

# date time now
dtn = lambda : re.sub('[-. :]', '', str(datetime.datetime.now())[:19])
a = lambda x: re.sub(',', '', x)

print dtn()
for line in bt.lines('GL_ISBS.txt'):
    #line = re.sub('\n', '', line)
    lino += 1
    if lino > 1:
        if len(str(lino)) > 5 and str(lino)[-6:] == '000000':
            #print dtn(), lino, amtDr, amtCr
            print dtn(), '\t', lino, '\t', "%20.f\t%20.f" %(amtDr, amtCr)
        cols = string.split(line, '^')
        if a(cols[4]) <> '0.00':
            amtDr += float(a(cols[4])) # as float
            #amtDr += D(a(cols[4])) # as decimal
        if a(cols[5]) <> '0.00':
            amtCr += float(a(cols[5])) # as float
            #amtCr += D(a(cols[5])) # as decimal
#print dtn(), lino, amtDr, amtCr
print dtn(), '\t', lino, '\t', "%20.f\t%20.f" %(amtDr, amtCr)
print dtn()


"""
float example
20081031121343
20081031121432  1000000                 112715030032            112715030032
20081031121523  2000000                 298082856981            298082856981
20081031121611  3000000                 392302756982            392302756982
20081031121659  4000000                 500343772842            500343745250
20081031121748  5000000                 618912481242            618912494721
20081031121837  6000000                 731253428490            731253428490
20081031121925  7000000                 851346825373            851346825373
20081031121959  7699585                1004659154083           1004659154083
20081031121959

decimal example
20081030202205
20081030202435 1000000 112715030032.47 112715030032.47
20081030202713 2000000 298082856980.99 298082856980.99
20081030202950 3000000 392302756981.93 392302756981.93
20081030203226 4000000 500343772842.48 500343745250.40
20081030203605 5000000 618912481241.68 618912494720.88
20081030203834 6000000 731253428489.99 731253428489.99
20081030204102 7000000 851346825372.71 851346825372.71
20081030204246 7699585 1004659154082.24 1004659154082.24
20081030204246
"""
